package com.zzy.product.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Collections;

/**
 * @Author kazu
 * @Date 2023/2/6 21:59
 * @Version 1.0
 */
@SuppressWarnings({"all"})
@Configuration
@EnableTransactionManagement	/*开启事务注解*/
@MapperScan({"com.zzy.product.mapper"})
public class MybatisConfig {
	
	/*3.5.*配置分页插件*/
	@Bean
	public MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
		PaginationInnerInterceptor innerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
		/*页数过大，直接去首页*/
		innerInterceptor.setOverflow(true);
		innerInterceptor.setMaxLimit(1000L);
		interceptor.addInnerInterceptor(innerInterceptor);
		return interceptor;
	}
	
	
	/**
	 * 用下面应该也可以
	 * TODO: 测试
	 */
	
//	@Bean
//	public PaginationInnerInterceptor paginationInnerInterceptor() {
//		PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
//		// 设置最大单页限制数量，默认 500 条，-1 不受限制
//		paginationInterceptor.setMaxLimit(-1L);
//		paginationInterceptor.setDbType(DbType.MYSQL);
//		// 开启 count 的 join 优化,只针对部分 left join
//		paginationInterceptor.setOptimizeJoin(true);
//		return paginationInterceptor;
//	}
//
//	@Bean
//	public MybatisPlusInterceptor mybatisPlusInterceptor(){
//		MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
//		mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor()));
//		return mybatisPlusInterceptor;
//	}
	


	
}














